package com.cql.framework.config.quartz;

import com.cql.framework.task.InsertMomentViewJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * TODO 定时器配置，这样简单配置还不够
 *
 * @author cql
 */
@Configuration
public class QuartzConfig {


    @Autowired
    public Scheduler scheduler;

    @PostConstruct
    public void initJob() throws SchedulerException {
        JobDetail jobDetail = JobBuilder.newJob(InsertMomentViewJob.class).build();
        Trigger trigger = TriggerBuilder
                .newTrigger()
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ? "))
                .build();
        scheduler.scheduleJob(jobDetail, trigger);
    }

}
